<div id="admin_code_tables">
  <p>
    <a href="<%= new_admin_code_table_path %>" class="btn btn-success btn-sm">
      <su-icon icon="plus" color="#fff" fix-width></su-icon>
      新增
    </a>
  </p>
  <%= grid(@code_tables, show_filters: :when_filtered) do |g|
    #g.action_column param_name: :select_ids, object_property: :id
    g.column name: "编号", attribute: 'id', ordering: true
    g.column name: "#{t 'activerecord.attributes.code_table.name'}", attribute: 'name' do |c|
      link_to c.name, admin_code_table_path(c.id)
    end
    # g.column name: "#{t 'activerecord.attributes.code_table.code'}", attribute: 'code'
    g.column name: "#{t 'activerecord.attributes.code_table.parent'}", assoc: :parent, attribute: 'name' do |c|
      link_to c.parent.name, admin_code_table_path(c.parent.id) if c.parent.present?
    end
    g.column name: "#{t 'activerecord.attributes.code_table.default_value'}", attribute: 'default_value'
    # g.column name: "#{t 'activerecord.attributes.code_table.is_public'}", attribute: 'is_public' do |c|
    #   '<su-icon icon="check" color="green"></su-icon>'.html_safe if c.is_public
    # end

    g.column do |c|
      add_child = ""
      add_child = link_to "#{new_admin_code_table_path}?parent_id=#{c.id}", class: [:btn, 'btn-xs', 'btn-primary'], :'v-su-tip' => '添加子项', :'tip-color' => 'primary', title: "#{t 'common.show'}" do
        "<i class='fa fa-plus fa-fw bigger-120'></i>".html_safe
      end if c.parent_id.nil?
      if c.is_public
        grid_operator(:admin_code_table_path, c.id, html: add_child)
      elsif c.default_value.nil? or c.default_value.blank?
        "<div class='visible-md visible-lg hidden-sm hidden-xs btn-group'>#{add_child}</div>".html_safe
      end
    end
  end %>
</div>
<script type="text/javascript" data-turbolinks-eval="true">
  new Vue({
    el: "#admin_code_tables",
    beforeCompile: function () {
    }
  })
</script>